import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ChatForm extends MyEvent{
	private JTextArea jtxtChatContent;
	private JTextArea jtxtMessage;
	private JButton jbtnSend;
	private JFrame jChatForm ;
	private JScrollPane jscrollContent, jscrollMsg;
	public ChatForm(){

		jChatForm = new JFrame();
		
		jtxtChatContent = new JTextArea(16	, 44);
		jtxtChatContent.setEnabled(false);
		jtxtChatContent.setLineWrap(true);
		jscrollContent = new JScrollPane(jtxtChatContent);
		
		jtxtMessage = new JTextArea(4, 36);
		jtxtMessage.setLineWrap(true);
		jscrollMsg = new JScrollPane(jtxtMessage);
		
		jbtnSend = new JButton("Send");
		jbtnSend.setPreferredSize(new Dimension(80, 63));
		jbtnSend.addActionListener(this);
	}
	
	public void CreateGUI(){
		jChatForm.add(jscrollContent);
		jChatForm.add(jscrollMsg);
		jChatForm.add(jbtnSend);
		jChatForm.setSize(500, 368);
		jChatForm.setResizable(false);
		jChatForm.setLayout(new FlowLayout());
		jChatForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jChatForm.setVisible(true);
	}
	
	public static void main(String[] args) {
		ChatForm chatform = new ChatForm();
		chatform.CreateGUI();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(jtxtMessage.getText().equals("")) return;
		if(e.getSource() == jbtnSend){
			jtxtChatContent.setText(jtxtChatContent.getText() + "\n" + jtxtMessage.getText());
		}
		jtxtMessage.setText("");
	}
}

